package com.burgeon.backend.Rest.User;
/**
 * 修改对应会员openid
 */
import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.service.ex.ErrorDataException;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class UserReadOpenid extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public UserReadOpenid(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */
    public void getData(String id,String openid) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(id,openid),url);

        String code = new JSONArray(str).getJSONObject(0).getString("code");
        if (!"0".equals(code)){
            throw new ErrorDataException("数据错误");
        }

    }

    private MultiValueMap Data(String id,String openid) {
        HashMap params = new HashMap();

        params.put("ID", id);
        params.put("partial_update","true");

        params.put("table", "C_VIP");//表名

        params.put("OPENID", openid);

        return DATA("ObjectModify", params,account,password);
    }


    public static void main(String[] args) {
        UserReadOpenid g = new UserReadOpenid("39.104.52.2:55321","zhaohong@bestone.net","666888");
        try {
            g.getData("312358","123");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
